package com.stars.module.common.service.impl;

import com.stars.base.constants.CommonNumberConstants;
import com.stars.base.entity.SessionUser;
import com.stars.module.common.service.CommonService;
import com.stars.util.cache.CacheUtil;
import com.stars.util.common.DevelopKit;
import org.springframework.stereotype.Service;

@Service
public class CommonServiceImpl implements CommonService {

    private final CacheUtil cacheUtil;

    public CommonServiceImpl(CacheUtil cacheUtil) {
        this.cacheUtil = cacheUtil;
    }

    @Override
    public boolean clearRedis() {
        SessionUser user = DevelopKit.getSessionUser();

        assert user != null;
        if (!CommonNumberConstants.NINETY_NINE_STR.equals(user.getUserType())) {
            // 如果不是管理员则禁止当前操作
            return false;
        }

        cacheUtil.clearCache();
        return true;
    }
}
